@extends('layout')
@section('head')
    @parent
@stop
@section('content')
    <div class="body_screening">
        <div class="screening_head">
            <p>正在热映
                {{--<a href="#">全部正在热映»</a>--}}
                {{--<a href="#">即将上映»</a>--}}
                {{--<button onclick="test()" value="button">123</button>--}}
            </p>
            <div class="slide_btn">
                <div class="slide_btn_right" onclick="slide_right()"></div>
                <div class="slide_btn_left" onclick="slide_left()"></div>
            </div>
            <div class="slide_num">
                <span id="slide_index">1</span>/
                <span id="slide_max">{{$num}}</span>
            </div>
        </div>

        <div class="screening_body">
                <ul class="ul" style="white-space:nowrap;position: absolute;font-size: 0px">
                    @foreach($screening as $item)
                    <li class="slide_items">
                        <ul>
                            <li class="slide_poster"><img style="width: 128px" src={{$item['poster']}}></li>
                            <li class="slide_title">{{$item['title']}}</li>
                            <li class="slide_rating">
                                @if($item['score']>9&&$item['score']<=10)
                                    <span class="rating_five"></span>
                                @elseif($item['score']<=9&&$item['score']>8)
                                    <span class="rating_fours"></span>
                                @elseif($item['score']<=8&&$item['score']>7)
                                    <span class="rating_four"></span>
                                @elseif($item['score']<=7&&$item['score']>6)
                                    <span class="rating_threes"></span>
                                @elseif($item['score']<=6&&$item['score']>5)
                                    <span class="rating_three"></span>
                                @elseif($item['score']<=5&&$item['score']>4)
                                    <span class="rating_twos"></span>
                                @elseif($item['score']<=4&&$item['score']>3)
                                    <span class="rating_two"></span>
                                @elseif($item['score']<=3&&$item['score']>2)
                                    <span class="rating_ones"></span>
                                @elseif($item['score']<=2&&$item['score']>1)
                                    <span class="rating_one"></span>
                                @elseif($item['score']<=1&&$item['score']>0)
                                    <span class="rating_zeros"></span>
                                @else
                                    <span class="rating_zero"></span>
                                @endif

                                @if($item['score']==null)
                                    <span class="rating_score" style="color: black">暂无评分</span>
                                @else
                                    <span class="rating_score">{{$item['score']}}</span>
                                @endif
                            </li>
                            <li class="slide_detail"><a href="detail/{{$item['id']}}">查看详情</a></li>
                        </ul>
                    </li>
                    @endforeach
                </ul>
        </div>
    </div>
    <div class="body_films">
        <div class="films_head">选电影
            @if(Session::get('nickname')=='张某昊')
                <a style="font-size: 9px" href="{{url('addFilm')}}">添加电影</a>
            @endif
        </div>
        <form id="tag" method="post">
            <div class="films_filter">
                <div class="films_tags">
                    <label id="tags_activate">热门<input type="radio" name="tag" value="热门" checked="checked"></label>
                    <label>最新<input type="radio" name="tag" value="最新"></label>
                    <label>经典<input type="radio" name="tag" value="经典"></label>
                    {{--<label>高分<input type="radio" name="tag" value="高分"></label>--}}
                    {{--<label>华语<input type="radio" name="tag" value="华语"></label>--}}
                    {{--<label>欧美<input type="radio" name="tag" value="欧美"></label>--}}
                    {{--<label>日韩<input type="radio" name="tag" value="日韩"></label>--}}
                    <label>剧情<input type="radio" name="tag" value="剧情"></label>
                    <label>动作<input type="radio" name="tag" value="动作"></label>
                    <label>喜剧<input type="radio" name="tag" value="喜剧"></label>
                    <label>爱情<input type="radio" name="tag" value="爱情"></label>
                    <label>科幻<input type="radio" name="tag" value="科幻"></label>
                    <label>悬疑<input type="radio" name="tag" value="悬疑"></label>
                    <label>惊悚<input type="radio" name="tag" value="惊悚"></label>
                    <label>冒险<input type="radio" name="tag" value="冒险"></label>
                    <label>犯罪<input type="radio" name="tag" value="犯罪"></label>
                    <label>战争<input type="radio" name="tag" value="战争"></label>
                    <label>历史<input type="radio" name="tag" value="历史"></label>
                    <label>动画<input type="radio" name="tag" value="动画"></label>
                </div>
                {{--<div class="films_sort">--}}
                {{--<div class="sort_items">--}}
                {{--<input type="radio" name="sort" value="热度" checked="checked">按热度排序--}}
                {{--<input type="radio" name="sort" value="时间">按时间排序--}}
                {{--<input type="radio" name="sort" value="评价">按评价排序--}}
                {{--</div>--}}
                {{--</div>--}}
            </div>
        </form>
        <div class="films_sort"></div>
        <div id="list_wrap" >
            <div id="films_list">
                @foreach($film as $item)
                    <a class="list_items" href="detail/{{$item['id']}}" id="f{{$i++}}">
                        <div class="items_poster">
                            <img src={{$item['poster']}}>
                        </div>
                        <div id="items_title" class="items_title">
                            {{$item['title']}}
                            <span id="items_score">
                                    @if($item['score']==0)
                                @else
                                    {{$item['score']}}
                                @endif
                                </span></div>
                    </a>
                @endforeach
            </div>
            <a class="list_more" href="javascript:;" onclick="more()">加载更多</a>
        </div>
    </div>
    <div class="body_review">
        <div class="user_profile">最受欢迎的影评</div>
        <div class="review_list">
            @foreach($review as $item)
                <div class="review_item" style="overflow: hidden">
                    <div class="review_img">
                        <a href="detail/{{$item['film_id']}}"><img src="{{$item['poster']}}"></a>
                    </div>
                    <div class="review_detail">
                        <a href="detail/{{$item['film_id']}}" style="font-size: 14px" class="review_title">{{$item['title']}}</a>
                        <div class="review_info"><a href="{{url('profile')}}/{{$item['user_name']}}">{{$item['user_name']}}</a>
                            @if($item['rating']>9&&$item['rating']<=10)
                                <span class="rating_five"></span>
                            @elseif($item['rating']<=9&&$item['rating']>8)
                                <span class="rating_fours"></span>
                            @elseif($item['rating']<=8&&$item['rating']>7)
                                <span class="rating_four"></span>
                            @elseif($item['rating']<=7&&$item['rating']>6)
                                <span class="rating_threes"></span>
                            @elseif($item['rating']<=6&&$item['rating']>5)
                                <span class="rating_three"></span>
                            @elseif($item['rating']<=5&&$item['rating']>4)
                                <span class="rating_twos"></span>
                            @elseif($item['rating']<=4&&$item['rating']>3)
                                <span class="rating_two"></span>
                            @elseif($item['rating']<=3&&$item['rating']>2)
                                <span class="rating_ones"></span>
                            @elseif($item['rating']<=2&&$item['rating']>1)
                                <span class="rating_one"></span>
                            @elseif($item['rating']<=1&&$item['rating']>0)
                                <span class="rating_zeros"></span>
                            @else
                                <span class="rating_zero"></span>
                            @endif
                            <span class="comment_time">{{$item['time']}}</span>
                            <span><img style="position: relative;top: 3px;" src="{{URL::asset('assets/img/praise.png')}}">{{$item['assist_num']}}</span></div>
                        <div class="review_content">{{$item['content']}}</div>
                    </div>
                </div>
            @endforeach
        </div>
    </div>
    <script>
        function test() {
            location.href="{{url('test2')}}";
        }
        function slide_right() {
            var index=$("#slide_index");
            var max=$("#slide_max");
            var i=parseInt(index.text());
            var m=parseInt(max.text());
            i++;
            if(i>m){
                i=1;
            }
            index.text(i);
            $(".ul").css('left',(2-i)*590);
            var margin_left=$(".body_screening").offset().left;
            var left=$(".ul").offset().left-margin_left-590;
            $(".ul").animate({left:left},"slow");
        }
        function slide_left() {
            var index=$("#slide_index");
            var max=$("#slide_max");
            var i=parseInt(index.text());
            var m=parseInt(max.text());
            i--;
            if(i<1){
                i=m;
            }
            index.text(i);
            if(i==m){
                $(".ul").css('left',-590*m);
            }
            var margin_left=$(".body_screening").offset().left;
            var left=$(".ul").offset().left-margin_left+590;
            $(".ul").animate({left:left},"slow");
        }
        function more() {
            //被隐藏影片
            var item=$(".list_items:hidden:first");
            var id=item.attr('id');
            if(id==null){
                $(".list_more").text('没有更多了');
            }
            else{
                id=id.substring(1,4);
                var i=parseInt(id);
                var j=i+20;
                for(i;i<j;i++){
                    $("#f"+i).show();
                }
            }
        }
        $(function () {
            function scrollPlay() {
                var index=$("#slide_index");
                var max=$("#slide_max");
                var i=parseInt(index.text());
                var m=parseInt(max.text());
                i+=1;
                if(i>m){
                    i=1;
                }
                index.text(i);
                $(".ul").css('left',(2-i)*590);
                var margin_left=$(".body_screening").offset().left;
                var left=$(".ul").offset().left-margin_left-590;
                $(".ul").animate({left:left},"slow");
            }
            function autoPlay() {
                var timer=setInterval(function () {
                    scrollPlay();
                },4000);
                $(".body_screening").hover(function () {
                    clearInterval(timer);
                },function () {
                    timer=setInterval(function () {
                        scrollPlay();
                    },4000);
                });
            }
            autoPlay();

           //悬停变色
            $("label").hover(function () {
                if($(this).attr('id')!='tags_activate'){
                    $(this).attr('id','tags_hover');
                }
            },function () {
                if($(this).attr('id')!='tags_activate'){
                    $(this).removeAttr('id');
                }
            });
            $(".rank_a").hover(function () {
                    $(this).attr('id','a_hover');
            },function (){
                    $(this).removeAttr('id');
            });
            //选择label标签下的input标签，即影片类型的单选按钮
            $("label input:first-child").click(function () {
                $("#tags_activate").removeAttr("id");//移除蓝色背景
                $(this).parent().attr("id","tags_activate");//添加蓝色背景
                $(".list_more").text('正在加载');
                $(".list_items").remove();
                $.post("{{url('tag')}}",
                    {
                        tag:$(this).val()
                    },
                    function (data) {
                        if(data!="no"){
                            var j=JSON.parse(data);
                            for(var i=0;i<j.length;i++){
                                //变量
                                var poster=j[i].poster;
                                var title=j[i].title;
                                var score=j[i].score;
                                if(score=='0'){
                                    score='';
                                }
                                var id=j[i].id;

                                //创建节点
                                var a=document.createElement("a");
                                var d_poster=document.createElement("div");
                                var img=document.createElement("img");
                                var d_title=document.createElement("div");
                                var t_title=document.createTextNode(title+" ");
                                var span=document.createElement("span");
                                var t_score=document.createTextNode(score);

                                //设置属性
                                a.setAttribute("class","list_items");
                                a.setAttribute("href","detail/"+id);
                                a.setAttribute("id","f"+(i+1));
                                d_poster.setAttribute("class","items_poster");
                                img.setAttribute("id","items_img"+i);
                                d_title.setAttribute("class","items_title");

                                //获取节点
                                var list=document.getElementById("films_list");


                                //追加节点
                                span.appendChild(t_score);
                                d_poster.appendChild(img);
                                a.appendChild(d_poster);
                                d_title.appendChild(t_title);
                                d_title.appendChild(span);
                                a.appendChild(d_title);
                                list.appendChild(a);


                                //赋值
                                var p=document.getElementById("items_img"+i);
                                p.setAttribute("src",poster);
                            }

                            $(".list_items").hide();
                            for(var i=1;i<=20;i++){
                                $("#f"+i).fadeIn("slow");
                            }
                            $(".list_more").text('加载更多');

                        }
                    });
            });
            //显示前20条
            $(".list_items").hide();
            for(var i=1;i<=20;i++){
                $("#f"+i).show();
            }
            //评论展开
//        var text=$(".review_content").text();
//        var content="";
//        if(text.length>115){
//            for(var n=0;n<115;n++){
//                content+=text[n];
//            }
//            content=content+'...';
//            $(".review_content").text(content);
//            var a=$("<a id='c1' href='javascript:;'>(全文)</a>");
//            $(".review_content").append(a);
//            $("#c1").click(function () {
//                $(".review_content").text(text);
//            });
//        }
        });
    </script>
@stop
@section('sidebar')
    @parent
    <div class="film_rank">豆辨电影TOP20</div>
    <ul id="rank_ul" style="list-style: none">
        <div hidden>{{$i=1}}</div>
        @foreach($rank as $item)
            <li class="rank_li"><span class="rank_span">{{$i++}}</span><a class="rank_a" href="{{url('detail')}}/{{$item['id']}}">{{$item['title']}}</a></li>
        @endforeach
    </ul>
@stop
@section('foot')
    @parent
@stop